<?php
class Helping_model extends Model {

    function get_helping()
    {
        $sql = "SELECT id FROM helping;";
        $query = $this->db->query($sql);
        return $query->result_array();
    }

    function insert_helping ($id)
    {
        try
        {
            $esc_id = $this->db->escape($id);
            $sql = "LOCK TABLES helping WRITE;";
            $this->db->query($sql);
            $sql = "SELECT id FROM helping WHERE id=$esc_id;";
            $query = $this->db->query($sql);
            if ($query->num_rows() > 0)
                {
                    $result = false;
                }
            else
                {
                    $sql = "INSERT INTO helping (id) values ($esc_id);";
                    $this->db->query($sql);
                    $result = true;
                }
            $sql = "UNLOCK TABLES;";
            $this->db->query($sql);
            return $result;
        }
        catch (Exception $e)
        {
            $sql = "UNLOCK TABLES;";
            $this->db->query($sql);
            return false;
        }
        
    }

    function remove_helping ($id)
    {
        $esc_id = $this->db->escape($id);
        $sql = "DELETE FROM helping WHERE id=$esc_id";
        $this->db->query($sql);
    }

}

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
